package com.usian.controller;

import com.usian.feign.ItemFeign;
import com.usian.pojo.TbItemCat;
import com.usian.pojo.TbItemParam;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("backend/itemParam")
public class ParamController {
    @Autowired
    private ItemFeign itemFeign;

    @RequestMapping("/selectItemParamByItemCatId/{itemCatId}")
    public Result selectItemParamByItemCatId(@PathVariable Integer itemCatId){
        TbItemParam tbItemParam=itemFeign.selectItemParamByItemCatId(itemCatId);
        if (tbItemParam!=null){
            return Result.ok(tbItemParam);
        }
        return Result.error("查询失败");

    }

    @RequestMapping("selectItemParamAll")
    public Result selectItemParamAll(){
        PageResult pageResult=itemFeign. selectItemParamAll();
        if (pageResult!=null &&pageResult.getResult().size()>0){
            return Result.ok(pageResult);
        }
        return Result.error("查询失败");

    }

    @RequestMapping("insertItemParam")
    public Result insertItemParam(@RequestParam Integer itemCatId,@RequestParam String paramData){
        int num=itemFeign.insertItemParam(itemCatId,paramData);
        if (num==1){
            return Result.ok();
        }
        return Result.error("添加失败");

    }

    @RequestMapping("deleteItemParamById")
    public Result deleteItemParamById(@RequestParam Integer id){
        int num=itemFeign.deleteItemParamById(id);
        if (num==1){
            return Result.ok();
        }
        return Result.error("删除失败");

    }
}
